home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 431_01 / com0.asm < prev    next >
Assembly Source File  |  1994-06-07  |  3KB  |  113 lines

  1. ;----------------------------------------------------------------------
  2. ;----------------------------------------------------------------------
  3. ;
  4. ; this is the assembly stub for COMIO. all of COMIO should
  5. ; probably be written in assembly for speed, but i've run
  6. ; into no speed problem having it in C
  7. ;
  8. ;----------------------------------------------------------------------
  9. ;----------------------------------------------------------------------
  10.  
  11. COM0_TEXT    segment    byte public 'CODE'
  12. DGROUP    group    _DATA,_BSS
  13.     assume    cs:COM0_TEXT,ds:DGROUP
  14. COM0_TEXT    ends
  15.  
  16. _DATA    segment word public 'DATA'
  17. d@    label    byte
  18. d@w    label    word
  19.  
  20. _DATA    ends
  21.  
  22. _BSS    segment word public 'BSS'
  23. b@    label    byte
  24. b@w    label    word
  25. _BSS    ends
  26.  
  27. extrn    _LSR:word
  28. extrn    _MSR:word
  29. extrn    _TRB:word
  30. extrn    _IIR:word
  31. extrn    _CommIO:far
  32.  
  33. public  _com0_init
  34. public  _com0_shutdown
  35. public    _com0
  36.  
  37. COM0_TEXT    segment    byte public 'CODE'
  38.  
  39. ;----------------------------------------------------------------------
  40. ; initialize this stub. grabs/sets int 60H and the serial interrupt
  41. ; passed on the stack
  42. ;----------------------------------------------------------------------
  43. _oldint        dd    ?    ; this points to the old INT 60 code
  44. _com0_init    proc    far
  45.         push    bp
  46.         mov    bp,sp
  47.         mov    ah,35h
  48.         int    21h
  49.         mov word ptr cs:[_oldint], bx
  50.         mov word ptr cs:[_oldint+2], es
  51.  
  52.         pop    bp
  53.         ret
  54. _com0_init    endp
  55.  
  56. ;----------------------------------------------------------------------
  57. ; restore the interrupts
  58. ;----------------------------------------------------------------------
  59. _com0_shutdown proc    far
  60.         ret
  61. _com0_shutdown endp
  62.  
  63. ;----------------------------------------------------------------------
  64. ; reset the PIC, save all registers, and call our I/O routine
  65. ; the [here] semaphore is probably unnecessary, but better safe
  66. ; than sorry
  67. ;----------------------------------------------------------------------
  68. here        db    0
  69. _com0           proc far
  70.         push    ax
  71.         mov    al,20h            ; re-enable PIC
  72.         out    20h, al
  73.         cmp    cs:[here],0        ; test semaphore
  74.         jnz    @@skip            ; skip if already here
  75.         mov    cs:[here],1        ; set semaphore
  76.         
  77.         push    ds
  78.         mov    ax,DGROUP
  79.         mov    ds,ax
  80.         
  81.         push    bx
  82.         push    cx
  83.         push    dx
  84.         push    si
  85.         push    di
  86.         push    es
  87.         push    bp
  88.         ;
  89.         ; for some reason at higher speeds on slow
  90.         ; machines, the machine will lock if i re-enable
  91.         ; interrupts here.
  92.         ;
  93.         ;sti
  94.         call    _CommIO            ; dispatch routine
  95.         ;cli                            ; no interrupts while
  96.                                                 ; resetting the stack
  97.         pop    bp            ; restore all registers
  98.         pop    es
  99.         pop    di
  100.         pop    si
  101.         pop    dx
  102.         pop    cx
  103.         pop    bx
  104.         pop    ds
  105.         mov    cs:[here],0        ; reset semaphore
  106. @@skip:
  107.         pop    ax
  108.         iret
  109. _com0        endp
  110. COM0_TEXT    ends
  111.         end
  112.         
  113.